//
//  AppDelegate.m
//  aixianfeng
//
//  Created by 李江波 on 2016/12/21.
//  Copyright © 2016年 lijiangbo. All rights reserved.
//

#import "AppDelegate.h"
#import "AIMainTabController.h"

#import "WYFeatureViewController.h"
#import "AIADViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    //通过kCFBundleVersionKey获取程序版本号信息，此处要强制转换成Nsstring形式
    NSString *versionKey = (NSString *)kCFBundleVersionKey;
    //去沙盒中取出上次使用过的版本号
    NSString *lastVersionCode = [[NSUserDefaults standardUserDefaults] objectForKey:versionKey];
    //加载程序中的info.plist文件获得当前程序的版本号
    NSString *nowValueCode = [NSBundle mainBundle].infoDictionary[versionKey];
    
    if ([lastVersionCode isEqualToString:nowValueCode]) {
        
        [self downloadADPicture];

    }else{
        //第一次使用软件，先把版本号写入沙盒
        [[NSUserDefaults standardUserDefaults] setObject:nowValueCode forKey:versionKey];
        //调用synchronize强制存储，如果不加则随机存储
        [[NSUserDefaults standardUserDefaults] synchronize];
        
        //显示新特性导航界面
        WYFeatureViewController *featureVc = [[WYFeatureViewController alloc]init];
        
        self.window.rootViewController = featureVc;
        
    }
    
    [_window makeKeyAndVisible];
    
    return YES;
}

-(void)downloadADPicture{
    
    if ([[NSUserDefaults standardUserDefaults] stringForKey:USERDEFAULTS] != nil) {
        
        self.window.rootViewController = [[AIADViewController alloc]init];
    }else{
        //没有缓存就先下载图片
        AIADViewController *adVC = [[AIADViewController alloc]init];
        
        [adVC loadData];
        self.window.rootViewController = [[AIMainTabController alloc]init];
    }
    
}



@end
